#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

  /* Prototypes */
void InitUART (unsigned char baudrate);
unsigned char ReceiveByte (void);
void TransmitByte (unsigned char data);

  /* Main - a simple test program */
int
main (void)
{
  unsigned char i;
  InitUART (207);                /* Set the baudrate to 2400 bps using a 8MHz crystal */
  for (;;)                      /* Forever */

    {
      //TransmitByte ('A');        /* Echo the received character */
      TransmitByte (ReceiveByte () + 1);        /* Echo the received character */
      for (i = 0; i < 200; i++);
    }
}


  /* Initialize UART */
void
InitUART (unsigned char baudrate)
{
  UBRRL = baudrate;             /*
                                   Set the baud rate */
  UCSRB = (UCSRB | _BV (RXEN) | _BV (TXEN));
  /* Enable UART receiver and transmitter */

  UCSRC = (1 << UCSZ1) | (1 << UCSZ0);

}

  /* Read and write functions */
unsigned char
ReceiveByte (void)
{
  while (!(UCSRA & (_BV (RXC))))        /* Wait for incomming data */
    ;

  /* Return the data */ return UDR;
}

void
TransmitByte (unsigned char data)
{
  while (!(UCSRA & (_BV (UDRE))))
    ;

  /* Wait for empty transmit buffer */
   UDR = data;

  /* Start transmittion */
}
